//package com.china.produce.service.impl;
//
//import com.china.produce.service.BookProducerService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.core.KafkaTemplate;
//import org.springframework.kafka.support.SendResult;
//import org.springframework.stereotype.Service;
//import org.springframework.util.concurrent.ListenableFuture;
//import org.springframework.util.concurrent.ListenableFutureCallback;
//
//
///**
// * @ClassName
// * @Author niujie
// * @Version
// * @Description
// * @CreateTime 2023/3/27
// */
//@Service
//public class BookProducerServiceImpl implements BookProducerService {
//
//    private static final Logger logger = LoggerFactory.getLogger(BookProducerServiceImpl.class);
//
//    @Autowired
//    private  KafkaTemplate<String, Object> kafkaTemplate;
//
//    public void sendMessage(String topic, Object o) {
//
//        ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(topic, o);
//        future.addCallback(new ListenableFutureCallback<SendResult<String, Object>>() {
//
//            @Override
//            public void onSuccess(SendResult<String, Object> sendResult) {
//                logger.info("生产者成功发送消息到" + topic + "-> " + sendResult.getProducerRecord().value().toString());
//            }
//            @Override
//            public void onFailure(Throwable throwable) {
//                logger.error("生产者发送消息：{} 失败，原因：{}", o.toString(), throwable.getMessage());
//            }
//        });
//    }
//}
